package com.myccb.app.view.investment;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.myccb.app.R;

public class DialogActivity extends Activity {
    private static final String ACTION_CLOSE_DIALOG = "REMOVE_DIALOG";
    @SuppressLint("HandlerLeak")
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1){
                TextView textView = findViewById(R.id.fromThirty);
                textView.setText(String.valueOf(Integer.parseInt((String) textView.getText()) - 1));
            }else
                finish();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog_investment);

    }

    @Override
    protected void onStart() {
        super.onStart();
        LinearLayout linearLayout = findViewById(R.id.linearLayout);
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(linearLayout,
                "rotation", 0f, 3600f);
        objectAnimator.setDuration(15000);
        objectAnimator.start();

        for (int i = 0; i < 30; i++) {
            handler.sendEmptyMessageDelayed(1, 2000 + i*2000);
        }
        handler.sendEmptyMessageDelayed(2, 10000);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

        if (ACTION_CLOSE_DIALOG.equals(intent.getAction())){
            finish();
        }
    }
}
